---
# Configuration for the nuancier webapp

- name: install needed packages
  package: name={{ item }} state=present
  with_items:
  - fedora-elections
  - python-psycopg2
  - python-openid-cla
  - python-openid-teams
  - python-memcached
  - libsemanage-python
  - python-alembic
  tags:
  - packages
  - elections

- name: replace the fedora-elections configuration file by the one with the normal user
  template: src={{ item.file }}
            dest="{{ item.location }}/{{ item.file }}"
            owner=apache group=apache mode=0600
  with_items:
  - { file: fedora-elections.cfg, location: /etc/fedora-elections }
  - { file: fedora-elections.conf, location: /etc/httpd/conf.d }
  - { file: fedora-elections.wsgi, location: /var/www }
  - { file: alembic.ini, location: /etc/fedora-elections }
  tags:
  - config
  - elections
  notify:
  - restart apache

- name: create the database scheme
  command: /usr/bin/python2 /usr/share/fedora-elections/fedora-elections_createdb.py
  environment:
      FEDORA_ELECTIONS_CONFIG: /etc/fedora-elections/fedora-elections.cfg
  changed_when: "1 != 1"
  tags:
  - config
  - elections
  notify:
  - restart apache

- name: set sebooleans so fedora-elections can talk to the db
  seboolean: name=httpd_can_network_connect_db
                    state=true
                    persistent=true
  tags:
  - selinux
  - elections

- name: apply selinux type to static files
  file: >
    dest=/usr/lib/python2.6/site-packages/fedora_elections/static/
    setype=httpd_sys_content_t
    state=directory
    recurse=yes
  tags:
  - selinux
  - elections

- name: apply selinux type to the wsgi file
  file: >
    dest=/usr/share/fedora-elections/fedora-elections.wsgi
    setype=httpd_sys_content_t
  tags:
  - selinux
  - elections

- name: set sebooleans so apache can talk to memcached0*
  seboolean: name=httpd_can_network_memcache
                    state=true
                    persistent=true
  tags:
  - selinux
  - elections
